package coop.bancocredicoop.proyectos.gd

import org.apache.commons.logging.LogFactory
import grails.transaction.Transactional

@Transactional(readOnly = true)
class DocumentTypeService {

    static final log = LogFactory.getLog(this)

    @Transactional
    def deleteDocumentType(documentTypeId) {
        def documentType = DocumentType.findById(documentTypeId, 
                                        [fetch: [fileTypes :"eager"]])
        def document = Document.findByDocumentType(documentType)
        if (document != null) {
            return [success: false, 
                    messageCode: 'documentType.deleted.alreadyUsed.message']
        }
        documentType.delete flush: true
        return [success: true,
                messageCode: 'documentType.deleted.message']
    }

}